﻿@using System.Reflection
@using CubicFWNet.Data.Models
@using CubicFWNet.Data.ViewModal
@using Newtonsoft.Json
@model CubicFWNet.Data.Models.Technology
@{
    //ViewBag.Title = "工艺详情";
    var product = ViewBag.Product as Product;
    var material = ViewBag.Material as Product;
    var orderProduct = ViewBag.OrderProduct as OrderProduct;
    var technologyManage = ViewBag.TechnologyManage as TechnologyManageView;
    var technologyItemList = ViewBag.TechnologyItemList as List<ProductTechnologyView>;
    Layout = "~/Views/Shared/_InfoPage.cshtml";
}
<section class="content">
    <div class="box box-default">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                @if (Model != null && technologyManage != null && product != null && material != null)
                {
                    <form class="form-horizontal" id="frmedit" action="@Url.Action("Add", "Technology")" method="post">
                        <input type="hidden" id="Id" name="Id" value="@Model.Id" />
                        <input type="hidden" id="OrderProductId" name="OrderProductId" value="@Model.OrderProductId" />
                        <input type="hidden" id="CreateTime" name="CreateTime" value="@Model.CreateTime" />
                        <input type="hidden" id="ApplyTime" name="ApplyTime" value="@Model.ApplyTime" />
                        <input type="hidden" id="Status" name="Status" value="@Model.Status" />
                        <div class="box-body">
                            <div class="form-group col-md-6">
                                <label for="ProductName" class="col-sm-3 control-label">产品名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ProductName" name="ProductName" value="@product.Name" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="Pack" class="col-sm-3 control-label">主料名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" value="@material.Name" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="Number" class="col-sm-3 control-label">工艺单编号</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Number" name="Number" placeholder="" value="@Model.Number" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="Pack" class="col-sm-3 control-label">基本单位</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Pack" name="Pack" value="@product.Pack" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="SizeWidth" class="col-sm-3 control-label">尺寸宽</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="SizeWidth" name="SizeWidth" value="@product.SizeWidth" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="SizeLenth" class="col-sm-3 control-label">尺寸长</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="SizeLenth" name="SizeLenth" value="@product.SizeLenth" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">数量</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control okeydown" data-des="数量" id="Amount" name="Amount" value="@orderProduct.Amount" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="SizeLenth" class="col-sm-3 control-label">分配类型</label>
                                <div class="col-sm-9">
                                    @if (Model.DistributeType == 1)
                                    {
                                        <input type="text" class="form-control" value="内部生产" readonly="readonly">
                                    }
                                    else
                                    {
                                        <input type="text" class="form-control" value="外购" readonly="readonly">
                                    }
                                </div>
                            </div>
                            @if (Model.DistributeType == 1)
                            {
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">左右间距-mm</label>
                                    <div class="col-sm-9">
                                        <input type="text" data-des="左右间距-mm" class="form-control okeydown" id="Space" name="Space" value="@Model.Space" readonly="readonly">
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">左右边距-mm</label>
                                    <div class="col-sm-9">
                                        <input type="text" data-des="左右边距-mm" class="form-control okeydown" id="Margin" name="Margin" value="@Model.Margin" readonly="readonly">
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">跳距-mm</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control okeydown" data-des="跳距-mm" id="Distance" name="Distance" value="@Model.Distance" readonly="readonly">
                                    </div>
                                </div>



                                <div class="form-group col-md-12" style="height: 1px;"></div>
                                <input type="hidden" id="modalData" value="@Model.Data" readonly="readonly">
                                <input type="hidden" id="otherData" value="@Model.TechnologyMemo" readonly="readonly">
                                <div id="other-content">

                                </div>
                                <div class="form-group col-md-12" style="height: 1px;"></div>
                                <div id="data-content">

                                </div>
                            }
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            @if (technologyItemList != null)
                            {
                                foreach (var item in technologyItemList)
                                {
                                    <div class="listProItem-content">
                                        <div class="form-group col-md-6">
                                            <label for="ProductName" class="col-sm-3 control-label">辅料名称</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" name="MaterialName" value="@item.ProductName" readonly="readonly">
                                                <input type="hidden" class="form-control" id="MaterialId" name="MaterialId" value="@item.ProductId">
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label for="ProductName" class="col-sm-3 control-label">辅料数量</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" id="Count" name="Count" value="@item.Count" readonly="readonly">
                                            </div>
                                        </div>
                                    </div>
                                }
                            }
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">给定用料长-mm</label>
                                <div class="col-sm-9">
                                    <label class="control-label" style="color: red">(尺寸长 + 跳距) * (数量 / 刀模数[左右])/1000</label>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">给定用料宽-mm</label>
                                <div class="col-sm-9">
                                    <label class="control-label" style="color: red">尺寸宽 * 刀模数[左右] + (刀模数[左右] - 1) * 左右间距 + 左右边距 * 2 +15</label>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">生产工时</label>
                                <div class="col-sm-9">
                                    <label class="control-label" style="color: red">(数量 / (刀模数[左右] * 刀模数[排])) / 设备频率-分钟+调机时间</label>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">检验工时</label>
                                <div class="col-sm-9">
                                    <label class="control-label" style="color: red">数量 / 检验频率-分钟</label>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">备注</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" rows="3" placeholder="请输入 ..." name="Memo" id="Memo" readonly="readonly">@Model.Memo</textarea>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;">
                            </div>
                            <div class="form-group col-md-6">
                                <label for="operationName" class="col-sm-3 control-label">操作人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationName" name="operationName" value="@Model.CreatorName" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="operationTime" class="col-sm-3 control-label">日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationTime" name="operationTime" value="@Model.CreateTime" readonly="readonly">
                                </div>
                            </div>
                        </div>
                    </form>
                }
            </div>
        </div>
    </div>
</section>
<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            $.reload();
                        }
                    });
                }
            });
            var yy = document.getElementById("modalData").value;
            if (yy != "") {
                var data = JSON.parse(document.getElementById("modalData").value);
                var $content = $('#data-content');
                var html = "";
                data.forEach(function (e, i) {
                    if (typeof e.value == "undefined") {
                        e.value = "";
                    }
                    if (typeof e.name == "undefined") {
                        e.name = "";
                    }
                    if (typeof e.des == "undefined") {
                        e.des = "未知";
                    }
                    html += "<div class='form-group col-md-6'>";
                    html += "<label for='j_a' class='col-sm-3 control-label'>" + e.des + "</label>";
                    html += "<div class='col-sm-9'>";
                    html += "<input type='text' class='form-control' id='" + e.name + "' name='" + e.name + "' value='" + e.value + "' readonly='readonly'>";
                    html += "</div></div>";
                });
                $content.append(html);
            }

            var xx = document.getElementById("otherData").value;
            if (xx != "") {
                var data1 = JSON.parse(document.getElementById("otherData").value);
                var $content1 = $('#other-content');
                var html1 = "";
                data1.forEach(function (e, i) {
                    if (typeof e.value == "undefined") {
                        e.value = "";
                    }
                    if (typeof e.name == "undefined") {
                        e.name = "";
                    }
                    if (typeof e.des == "undefined") {
                        e.des = "未知";
                    }
                    html1 += "<div class='form-group col-md-6'>";
                    html1 += "<label for='j_a' class='col-sm-3 control-label'>" + e.des + "</label>";
                    html1 += "<div class='col-sm-9'>";
                    html1 += "<input type='text' class='form-control' id='" + e.name + "' name='" + e.name + "' value='" + e.value + "' readonly='readonly'>";
                    html1 += "</div></div>";
                });
                $content1.append(html1);
            }
        });


        $("#j_sw,#j_sl").keyup(function () {
            var width = $("#j_sw").val(); //给定宽
            var length = $("#j_sl").val(); //给定长
            if (isNaN(width) || width == "" || width == "Infinity" || width == "NaN") {
                width = 0;
                $("#j_sw").val("");
                return;
            }
            if (isNaN(length) || length == "" || length == "Infinity" || length == "NaN") {
                length = 0;
                $("#j_sl").val("");
                return;
            }
            var oriwidth = $("#SizeWidth").val(); //原始宽
            var orilength = $("#SizeLenth").val(); //原始长
            if (isNaN(oriwidth) || oriwidth == "Infinity" || oriwidth == "NaN") {
                oriwidth = 0;
            }
            if (isNaN(orilength) || orilength == "Infinity" || orilength == "NaN") {
                orilength = 0;
            }
            var amount = $("#Amount").val();
            var wasteratio = (((oriwidth * orilength) / (width * length)) / 1).toFixed(2);
            var widthratio = ((oriwidth / width) / 1).toFixed(2);
            var lengthratio = ((orilength / length) / 1).toFixed(2);
            $("#j_Waste").val(wasteratio);
            $("#j_ww").val(widthratio);
            $("#j_wh").val(lengthratio);
            var j_cost = oriwidth * orilength * amount;
            $("#j_cost").val(j_cost); //直接成本
        });

        $(".okeydown").on("keydown", function () {
            var k = event.keyCode;
            if ((k <= 57 && k >= 48) || (k <= 105 && k >= 96) || (k == 8) || (k == 110) || (k == 190)) {
                return true;
            } else {
                return false;
            }
        });

    </script>
}

